import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
  ParseIntPipe,
} from '@nestjs/common';
import { ApiOperation } from '@nestjs/swagger';
import { RoleService } from './role.service';
import { CreateRoleDto } from './dto/create-role.dto';
import { UpdateRoleDto, MergedRoleQueryDto } from './dto/update-role.dto';
import { Permissions } from '../public/public.decorator';
import { LogOperationTitle } from 'src/common/decorator/oprertionlog.decorator';

@Controller('role')
export class RoleController {
  constructor(private readonly roleService: RoleService) {}

  @Post()
  @Permissions('create')
  @LogOperationTitle('创建角色')
  @ApiOperation({ summary: '创建角色' })
  create(@Body() createRoleDto: CreateRoleDto) {
    return this.roleService.create(createRoleDto);
  }

  @Get('get-all-roles')
  @Permissions('read')
  @LogOperationTitle('获取所有角色')
  @ApiOperation({ summary: '获取所有角色' })
  findAll(@Query() params: MergedRoleQueryDto) {
    return this.roleService.findAll(params);
  }

  @Get(':id')
  @Permissions('read')
  @LogOperationTitle('获取角色详情')
  @ApiOperation({ summary: '获取角色详情' })
  findOne(@Param('id', ParseIntPipe) id: number) {
    return this.roleService.findOne(id);
  }

  @Patch(':id')
  @Permissions('update')
  @LogOperationTitle('更新角色')
  @ApiOperation({ summary: '更新角色' })
  update(
    @Param('id', ParseIntPipe) id: number,
    @Body() updateRoleDto: UpdateRoleDto,
  ) {
    return this.roleService.update(id, updateRoleDto);
  }

  @Delete(':id')
  @Permissions('delete')
  @LogOperationTitle('删除角色')
  @ApiOperation({ summary: '删除角色' })
  remove(@Param('id', ParseIntPipe) id: number) {
    return this.roleService.remove(id);
  }
}
